import {loginComplete} from "../service/User"
export default function (Page) {
    // 返回一个新的 Page 构造器
    return (function (page) {

        // 获取需要hook的方法, 保存方法的原始实现
        const {onLoad, onShow, onShareAppMessage, onShareTimeline} = page;

        /**
         * @method 重写 onLoad 方法
         */
        page.onLoad = async function (options) {
            // 改写内容
            if (typeof onLoad === "function") {
                console.log(loginComplete)
                await loginComplete();
                console.log(loginComplete)
                onLoad.call(this, options);
            }
        }

        /*重写onShareAppMessage*/
        if (typeof onShareAppMessage === "function") {
            page.onShareAppMessage = function (res) {
                let data = onShareAppMessage.call(this) || {};
                if (Object.keys(data).length > 0) {
                    return data
                } else {
                    return {
                        title: "汇鸿汇升",
                        path: "/pages/home/index/index"
                    }
                }
            }
        }

        /*重写onShareTimeline*/
        if (typeof onShareTimeline === "function") {
            page.onShareTimeline = function (res) {
                let data = onShareTimeline.call(this) || {};
                if (Object.keys(data).length > 0) {
                    return data
                } else {
                    return {
                        title: "汇鸿汇升",
                        path: "/pages/home/index/index"
                    }
                }
            }
        }

        // 调用原来的构造方法
        return Page(page);
    });
}